all files / src/ h.js

100% Statements 38/38
93.33% Branches 28/30
100% Functions 2/2
100% Lines 33/33
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73    10× 10×   10×   10×   10×   10×   10×   10×                     220×           220×               217× 118× 118× 112× 112×   110× 110×   112× 115×   115× 115× 13× 102× 102×   115×       217× 217× 217×     10×  
'use strict';
 
exports.__esModule = true;
exports['default'] = h;
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
 
var _vnode = require('./vnode');
 
var _vnode2 = _interopRequireDefault(_vnode);
 
var _hooks = require('./hooks');
 
var _util = require('./util');
 
var SHARED_TEMP_ARRAY = [];
 
/** JSX/hyperscript reviver
 *	@see http://jasonformat.com/wtf-is-jsx
 *	@public
 *  @example
 *  /** @jsx h *\/
 *  import { render, h } from 'preact';
 *  render(<span>foo</span>, document.body);
 */
 
function h(nodeName, attributes) {
	var len = arguments.length,
	    attributeChildren = attributes && attributes.children,
	    children = undefined,
	    arr = undefined,
	    lastSimple = undefined;
 
	if (attributeChildren) {
		delete attributes.children;
 
		// if (len<3) {
		// 	unfilteredChildren = attributeChildren;
		// 	start = 0;
		// }
		if (len < 3) return h(nodeName, attributes, attributeChildren);
	}
 
	for (var i = 2; i < len; i++) {
		var _p = arguments[i];
		if (_util.falsey(_p)) continue;
		if (!children) children = [];
		if (_p.join) {
			arr = _p;
		} else {
			arr = SHARED_TEMP_ARRAY;
			arr[0] = _p;
		}
		for (var j = 0; j < arr.length; j++) {
			var child = arr[j],
			    simple = !_util.falsey(child) && !(child instanceof _vnode2['default']);
			if (simple) child = String(child);
			if (simple && lastSimple) {
				children[children.length - 1] += child;
			} else Eif (!_util.falsey(child)) {
				children.push(child);
			}
			lastSimple = simple;
		}
	}
 
	var p = new _vnode2['default'](nodeName, attributes || undefined, children || undefined);
	_hooks.optionsHook('vnode', p);
	return p;
}
 
module.exports = exports['default'];